package com.example.petstore;

import dao.mysql.UserDAO;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Date;


public class Controller {

    @FXML
    private TextField Account;
    @FXML
    private TextField Password;
    @FXML
    private Button CloseButton;
    @FXML
    private Button Login;
    @FXML
    private Button Back;
    private Button Select;
    @FXML
    private Button Reset;
    private Button AddToCart;
    @FXML
    private Button CheckCart;
    @FXML
    private Button ReturnList;
    @FXML
    private Button SubmitOrder;
    @FXML
    private Button OrderClose;
    public void Login(ActionEvent event) throws IOException {

        if(Account.getText().isBlank() == false && Password.getText().isBlank() == false){

            UserDAO userdao = new UserDAO();
            if(userdao.validateLogin(Account.getText(),Password.getText())==0) {
                Stage primaryStage = (Stage) Login.getScene().getWindow();
                primaryStage.close();//打开新的窗口 关闭当前的窗口
                ProductList list = new ProductList();//新窗口类首页窗口
                list.List();//打开新窗口
            }
            else {
                LoginFailed Failed = new LoginFailed();
                Failed.Failed();

            }

        }
        else {
            LoginFailed Failed = new LoginFailed();
            Failed.Failed();

        }
    }

    public void Close(ActionEvent actionEvent) {
        Stage close = (Stage) CloseButton.getScene().getWindow();
        close.close();
    }
    public void Back(ActionEvent actionEvent) throws IOException {
        Stage back = (Stage) Back.getScene().getWindow();
        back.close();
    }
    public void Shop(ActionEvent actionEvent) throws IOException {
        Stage check = (Stage) CheckCart.getScene().getWindow();
        check.close();//打开新的窗口 关闭当前的窗口
        ProductCart cart = new ProductCart();//新窗口类首页窗口
        cart.Cart();//打开新窗口
    }
    public void Cart(ActionEvent actionEvent) throws IOException {
        Stage reenlist = (Stage) ReturnList.getScene().getWindow();
        reenlist.close();//打开新的窗口 关闭当前的窗口
        ProductList list = new ProductList();//新窗口类首页窗口
        list.List();//打开新窗口

    }
    public void Cart1(ActionEvent actionEvent) throws IOException {
        Stage submit = (Stage) SubmitOrder.getScene().getWindow();
        Order order = new Order();//新窗口类首页窗口
        order.Order();//打开新窗口
    }
    public void Order(ActionEvent actionEvent) throws IOException {
        Stage order = (Stage) OrderClose.getScene().getWindow();
        order.close();
    }
}

